# Maintainer: Junjie Mao <eternal.n08@gmail.com>

_realname=ocaml-lablgtk
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.18.3
pkgrel=2
pkgdesc="An Ocaml interface to the GIMP Tool Kit (mingw-w64)"
arch=('any')
url='http://lablgtk.forge.ocamlcore.org/'
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gtk2"
         "${MINGW_PACKAGE_PREFIX}-gtksourceview2"
         "${MINGW_PACKAGE_PREFIX}-gtkspell"
         "${MINGW_PACKAGE_PREFIX}-libglade"
         "${MINGW_PACKAGE_PREFIX}-libgnomecanvas"
         "${MINGW_PACKAGE_PREFIX}-libglade"
         "${MINGW_PACKAGE_PREFIX}-ocaml"
         "${MINGW_PACKAGE_PREFIX}-ocaml-findlib"
         )
makedepends=("${MINGW_PACKAGE_PREFIX}-flexdll"
             "${MINGW_PACKAGE_PREFIX}-ocaml-camlp4"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=("https://forge.ocamlcore.org/frs/download.php/1479/lablgtk-${pkgver}.tar.gz"
        "0001-Fix-a-path-issue-during-installation.patch")
sha256sums=('975bebf2f9ca74dc3bf7431ebb640ff6a924bb80c8ee5f4467c475a7e4b0cbaf'
            'b96ad79d62bd227e57a63101fedd8ac1e30965c4981fda4d1dcbff89438b53f7')

prepare() {
  cd ${srcdir}/lablgtk-${pkgver}
  patch -p1 -i ${srcdir}/0001-Fix-a-path-issue-during-installation.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf lablgtk-${pkgver} build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-gtktest

  sed -i "s/-pthread/-lpthread/g" config.make
  make
  make opt
}

check() {
  # The package does not include an automatic test process
  plain "skip"
}

package() {
  cd ${srcdir}/${_pkgsrc}
  make install DESTDIR="${pkgdir}"

  for f in COPYING LGPL; do
    [ -f ${f} ] && install -Dm644 ${f} ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/${f}
  done

  # do not append to ld.conf
  rm ${pkgdir}${MINGW_PREFIX}/lib/ocaml/ld.conf
}
